#!/usr/bin/node

const log = console.log,
      http = require('http'),
      url = require('url');

http.createServer((req,res)=>{
  let addr = url.parse(req.url);
  if(addr.pathname!=='/'){
    res.statusCode = 404;
    res.setHeader('Content-Type','text/html');
    res.end('<h1>Not Found 404</h1>');
    return ;
  }

  let data = '';
  req.setEncoding('binary')
  req.on('data',chunk => data += chunk);
  req.on('end',()=>{
    data = data.split('\r\n');
    let file = data[1].split('; ');
    let filename = file[2].split('=')[1];
    let msg = data[4];
    log(msg);
    log('filename:',filename);
    
    //log(datanew);
    //log(datanew[1]);
    //log(datanew[4]);
    res.end('ok');
  })

}).listen(8080);
